﻿using Core;

namespace g_gongjianta.battle.fsm.anchor
{
    public class IdleFsmState : AbstractSkillState
    {
        public override int Kind => (int)EWholeState.Idle;

        protected override void Init()
        {
            base.Init();

            funcList.Add(CheckAttackFunc);

            delayList.Add(CheckIdleFunc);
        }

        public override void Enter()
        {
            // log.d("Anchor.IdleState.Enter");

            if (SkillId == 0)
            {
                SkillId = character.TblSkill.IdleId;
            }

            conf = mTable.Find(SkillId);

            base.Enter();
        }

        protected override void Confirm()
        {
            base.Confirm();

            skillSrl = mSkill.Use(SkillId);
        }

        public override void Exit()
        {
            // log.d("Anchor.IdleState.Exit");

            base.Exit();
        }

        private void CheckAttackFunc()
        {
            var triggerID = PollingAttackSkill();

            if (triggerID > 0)
            {
                wholeRecord.Trigger((int)EWholeState.Attack, triggerID);
            }
        }

        private void CheckIdleFunc()
        {
            if (mSkill.IsRunning(skillSrl)) return;

            var triggerID = conf.LinkDefault;
            if (triggerID > 0)
            {
                wholeRecord.Trigger((int)EWholeState.Idle, triggerID);
            }
        }
    }
}